'use client'

import React from 'react';
import { BaseEditorProps } from './types';

export default function MarqueeEditor({ properties, updateProperty, handleFileSelect }: BaseEditorProps) {
  return (
    <div className="space-y-4">
      <div className="space-y-3">
        <div>
          <label className="block text-sm font-medium text-gray-700 mb-1">方向</label>
          <select
            className="w-full p-2 border border-gray-300 rounded"
            value={properties.direction || "left"}
            onChange={(e) => updateProperty('direction', e.target.value)}
          >
            <option value="left">向左</option>
            <option value="right">向右</option>
          </select>
        </div>
        <div>
          <label className="block text-sm font-medium text-gray-700 mb-1">速度</label>
          <input
            type="number"
            className="w-full p-2 border border-gray-300 rounded"
            value={properties.speed || 20}
            onChange={(e) => updateProperty('speed', parseInt(e.target.value))}
          />
        </div>
        <div>
          <label className="block text-sm font-medium text-gray-700 mb-1">图片样式 (CSS类名)</label>
          <input
            type="text"
            className="w-full p-2 border border-gray-300 rounded"
            value={properties.className || "h-50 w-auto object-contain"}
            onChange={(e) => updateProperty('className', e.target.value)}
            placeholder="h-50 w-auto object-contain"
          />
        </div>
      </div>

      <div>
        <h3 className="font-medium text-gray-800 mb-3">图片列表</h3>
        <div className="space-y-3">
          {(properties.images || []).map((img: string, index: number) => (
            <div key={index} className="border border-gray-200 rounded p-3 bg-gray-50">
              <div className="space-y-2">
                <div>
                  <label className="block text-xs text-gray-600 mb-1">图片URL</label>
                  <input
                    type="text"
                    className="w-full p-2 border border-gray-300 rounded text-sm"
                    value={img || ""}
                    onChange={(e) => {
                      const newImages = [...(properties.images || [])];
                      newImages[index] = e.target.value;
                      updateProperty('images', newImages);
                    }}
                    placeholder="图片URL"
                  />
                </div>
                <div>
                  <label className="block text-xs text-gray-600 mb-1">上传图片</label>
                  <input
                    type="file"
                    accept="image/*"
                    onChange={(e) => handleFileSelect(e, { type: 'marquee', index })}
                    className="w-full text-sm file:mr-1 file:py-1 file:px-2 file:rounded file:border file:text-xs file:font-medium file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100"
                  />
                </div>
                <button
                  type="button"
                  className="text-red-500 hover:text-red-700 text-sm"
                  onClick={() => {
                    const newImages = [...(properties.images || [])];
                    newImages.splice(index, 1);
                    updateProperty('images', newImages);
                  }}
                >
                  删除此图片
                </button>
              </div>
            </div>
          ))}
          <button
            type="button"
            className="w-full py-2 border-2 border-dashed border-gray-300 rounded text-gray-500 hover:border-gray-400 hover:text-gray-600 text-sm"
            onClick={() => {
              const newImages = [...(properties.images || []), ""];
              updateProperty('images', newImages);
            }}
          >
            + 新增图片
          </button>
        </div>
      </div>
    </div>
  );
}
